﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class SYS_CaseCauseSimilarDAL
    {
        /// <summary>
        ///  增加相似违法行为数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddCaseCauseSimilar(SYS_CaseCauseSimilar model)
        {
            try
            {
                string sql = $@"INSERT INTO [Ldt_JudgeDocSystem].[dbo].[SYS_CaseCauseSimilar]
           ([CCS_ID]
           ,[CC_ID]
           ,[CCS_SimilarID]
           ,[CCS_State]
           ,[UpdateTime])
     VALUES
           ('{model.CCS_ID}','{model.CC_ID}','{model.CCS_SimilarID}',{model.CCS_State},'{model.UpdateTime}')";
                Database db = DatabaseFactory.CreateDatabase("JudgeDoc");
                DbCommand oCmd = db.GetSqlStringCommand(sql.ToString());
                int obj = db.ExecuteNonQuery(oCmd);
                if (obj > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("添加相似数据出错："+ex.Message);
                return false;
            }
        }

        /// <summary>
        ///  删除相似违法行为数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool DelCaseCauseSimilar(string  ccsId)
        {
            try
            {
                string sql = $@" delete from [Ldt_JudgeDocSystem].[dbo].[SYS_CaseCauseSimilar] where CCS_ID='{ccsId}' ";
                Database db = DatabaseFactory.CreateDatabase("JudgeDoc");
                DbCommand oCmd = db.GetSqlStringCommand(sql.ToString());
                int obj = db.ExecuteNonQuery(oCmd);
                if (obj > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("删除相似数据出错：" + ex.Message);
                return false;
            }
        }

        /// <summary>
        ///  修改相似违法行为数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateCaseCauseSimilar(string ccsId,string ccsState)
        {
            try
            {
                string sql = $@" update SYS_CaseCauseSimilar set CCS_State = {ccsState} where CCS_ID = '{ccsId}' ";
                Database db = DatabaseFactory.CreateDatabase("JudgeDoc");
                DbCommand oCmd = db.GetSqlStringCommand(sql.ToString());
                int obj = db.ExecuteNonQuery(oCmd);
                if (obj > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("删除相似数据出错：" + ex.Message);
                return false;
            }
        }

        

    }
}
